package lesson6.example3;

import java.lang.management.ManagementFactory;
import java.net.URISyntaxException;

import sun.jvmstat.monitor.*;


// 在底层，HotSpot通过perfData接口来提供这些数据；注册数据的实现在services目录里
public class Test {
	static final String YOUNG_GC_MONITOR_NAME = "sun.gc.collector.0.invocations";
	static final String FULL_GC_MONITOR_NAME = "sun.gc.collector.1.invocations";

	static Monitor youngGCMonitor = null;
	static Monitor fullGCMonitor = null;


	public static void main(String args[]) {
		try {
			VmIdentifier vmId = new VmIdentifier("5809");
			MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);

			MonitoredVm mv = monitoredHost.getMonitoredVm(vmId, 0);
			youngGCMonitor = mv.findByName(YOUNG_GC_MONITOR_NAME);
			fullGCMonitor = mv.findByName(FULL_GC_MONITOR_NAME);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println(youngGCMonitor.getValue());
		System.out.println(fullGCMonitor.getValue());
		
	}

}
